/*
 * @Description: 
 * @Author: tianleilei1
 * @Date: 2021-05-26 10:54:50
 * @LastEditTime: 2021-05-26 14:18:47
 * @LastEditors: tianleilei1
 */
/**
 * @description: forEach函数
 * @param {*} array
 * @param {*} fn
 */
function forEach(array,fn){
  for(let i = 0; i< array.length; i++) {
    fn(array[i],i)
  }
}
/**
 * @description: filter函数
 * @param {*} array
 * @param {*} fn
 */
function filter(array,fn) {
  let arr = []
  for(let i = 0; i< array.length; i++) {
    if(fn(array[i])){
      arr.push(array[i])
    }
  }
  return arr
}
/**
 * @description: once函数
 * @param  {*}
 * @return {*}
 * @param {*} fn
 */
function once(fn){
  let done = false
  return function(){
    if(!done){
      done = true
      return fn.apply(this,arguments)
    }
    
  }
}
function checkAge(min){
  return function(age){
    return age > min
  }
}
// let checkAge18 = checkAge(18)
// console.log(checkAge18(20))
// console.log(checkAge18(13))
const arr = [3,5,7,2,4,7,2,4]
// forEach(arr,(item,index)=>{
//   console.log('item',item,index)
// })
// const newArr = filter(arr,item=>{
//   return item > 5
// })
// console.log(newArr)
// let f = once(item=>{return item % 2})
// console.log(f(3))
// console.log(f(5))
// console.log(f(7))
